#include <stdio.h>

typedef unsigned float_bits;

float_bits float_f2i(float_bits f);
float u2f(unsigned x);

int main()
{
	unsigned i = 0x00000001;
	printf("%d\t%d\n", (int)u2f(i), float_f2i(i));
	i = 0x43800000;
	printf("%d\t%d\n", (int)u2f(i), float_f2i(i));
	i = 0x4E800000;
	printf("%d\t%d\n", (int)u2f(i), float_f2i(i));
	i = 0xFFFFFFFF;
	printf("%d\t%d\n", (int)u2f(i), float_f2i(i));
    	return 0;
}

float_bits float_f2i(float_bits f)
{
	unsigned sign = f >> 31;
	unsigned exp = f >> 23 & 0xFF;
	unsigned frac = f & 0x7FFFFF;
	unsigned bias = 127;
	unsigned num;
	unsigned E, M;

	if (exp >= 0 && exp < 0 + bias)
		num = 0;
	else if (exp >= 31 + bias)
		num = 0x80000000;
	else {
		E = exp - bias;
		M = frac | 0x800000;
		if (E > 23)
			num = M << (E -23);
		else 
			num = M >> (23 - E);
	}
	return sign ? -num : num; 
}

float u2f(unsigned x)
{
	return *(float *)&x;
}
